// ------------- Class WordGrp ------------- //
// -------------- WordGrp.cpp ------------- //

using namespace std;
#include <iostream>

#include "WordGrp.h"
#include "Word.h"

void WordGrp::AddWordGrp(Expression* exp)
{
	wordGrp.push_back(exp);
}

void WordGrp::Display()
{
	cout << "[";
	for(unsigned int i = 0; i < wordGrp.size(); i++)
		(*wordGrp[i]).Display();
	cout << "]";
}

bool WordGrp::IsTheSame(string findWord)
{
	bool result = false;
	unsigned int i = 0;

	while(i < wordGrp.size() && result == false)
	{
		result = (*wordGrp[i]).IsTheSame(findWord);
		++i;
	}

	return result;
}

WordGrp::WordGrp(string newString, string lang)
{
	for (unsigned int i = 1; i < newString.length()-1; i++)
	{
		string tempString;
		int cptCrochet = 0;

		if(newString[i] == '[')
		{
			while(newString[i] != ']' || cptCrochet != -1)
			{
				tempString += newString[i++];
				if(newString[i] == '[')
					cptCrochet++;

				if(newString[i] == ']')
					cptCrochet--;
			}

			tempString += "]";
			wordGrp.push_back(new WordGrp(tempString, lang));
			i++;
		}
		else
		{
			string tempWord;

			while(newString[i] != ' ' && newString[i] != ']')
			{
				tempWord += newString[i++];
			}
			wordGrp.push_back(new Word(tempWord, lang));
		}
	}
}

WordGrp::WordGrp () {}


WordGrp::~WordGrp () {}

